package igrupobbva.pe.sistemareniec.util;
import java.io.IOException;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ExportarExcelServlet extends HttpServlet implements Servlet {
	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public ExportarExcelServlet() {
		super();
	}

	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest arg0, HttpServletResponse arg1)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest arg0, HttpServletResponse arg1)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("iso-8859-1");				
		String strArchivo = "ReporteConsultasReniec.xls";
    	response.setHeader("Content-Disposition","attachment; filename="+strArchivo);
		response.setContentType("application/vnd.ms-excel"); 
		org.apache.poi.hssf.usermodel.HSSFWorkbook libro = (org.apache.poi.hssf.usermodel.HSSFWorkbook )request.getSession().getAttribute("libro");
		java.io.BufferedOutputStream elFichero = new java.io.BufferedOutputStream(response.getOutputStream());
		libro.write(response.getOutputStream());
		elFichero.close();
	}

}